<?php
require('includes/top.php');

$laptop_model = $_POST['laptop_model'];
$emp_company_name = $_POST['emp_company_name'];
for ($i = 0; $i <count($_POST[acc_data]); $i++) {
$acc = $_POST[acc_data][$i];

$acc_id_array = explode('-',$acc);
$acc_array = explode('-',$emp_company_name);

if($acc_id_array[1]!="Data card")
{
$sql="INSERT INTO used_accessories_data(`accessoriesdata_id`,`accessories_name`,`laptop_id`) VALUES ('$acc_id_array[0]','$acc_id_array[1]','$laptop_model')";

$result = mysql_query($sql);

}
else
{

$sql="INSERT INTO used_accessories_data(`accessoriesdata_id`,`accessories_name`,`company_name`,`card_no`,`laptop_id`) VALUES ('$acc_id_array[0]','$acc_id_array[1]','$acc_array[0]','$acc_array[1]','$laptop_model')";

$result = mysql_query($sql);

$sql2="UPDATE data_card SET `status` = '1' WHERE card_no = '".$acc_array[1]."'";
$result2=mysql_query($sql2);

}

}
if($result>0)
{
header('Location: assign_acc_to_lap.php?v=success');
}
else
{
header('Location: assign_acc_to_lap.php?v=err');
}
?>